import axios from 'axios';

const AMAP_API_KEY = '7f7a58932a276710392d574317aacdf4'; // 替换为您的高德API Key
const AMAP_WEATHER_URL = 'https://restapi.amap.com/v3/weather/weatherInfo';

export const getAmapWeather = async (city: string) => {
  try {
    const response = await axios.get(AMAP_WEATHER_URL, {
      params: {
        key: AMAP_API_KEY,
        city: city,
        extensions: 'base', // base: 实时天气；all: 天气预报
      },
    });
    return response.data;
  } catch (error) {
    console.error('Error fetching weather data:', error);
    return null;
  }
};